package cn.com.oceansoft.business.os.service.impl;

import cn.com.oceansoft.business.base.entity.Pager;
import cn.com.oceansoft.business.base.entity.Query;
import cn.com.oceansoft.business.base.entity.Result;
import cn.com.oceansoft.business.os.entity.Show;
import cn.com.oceansoft.business.os.entity.ShowResult;
import cn.com.oceansoft.business.os.persistence.IShowMapper;
import cn.com.oceansoft.business.os.service.IShowService;
import cn.com.oceansoft.nos.common.util.web.PageUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by zhangxl on 2016/12/22.
 */

@Service
public class ShowServiceImpl implements IShowService{

    @Resource
    private IShowMapper showMapper;

    @Override
    public Pager<Show> findShowByPage(Query query) {
        PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
        Page<Show> page = (Page<Show>) showMapper.findShow(query);
        return PageUtil.page2pager(page, query);

    }

    @Override
    public Pager<Show> findShowByPageP(Query query) {
        PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
        Page<Show> page = (Page<Show>) showMapper.findShowP(query);
        return PageUtil.page2pager(page, query);

    }

    @Override
    @Transactional
    public Result saveShow(Show show) {
        int row = showMapper.addShow(show);
        if(row > 0){
            return new Result(Result.SUCC, "新增成功");
        } else {
            return new Result(Result.FAILURE, "新增失败");
        }

    }

    @Override
    public Show findShowById(int showId) {
        return showMapper.findShowById(showId);
    }

    @Override
    public Result updateShow(Show show) {
        int rt = showMapper.updateShow(show);
        if (rt == 1) {
            return new Result();
        } else {
            return new Result(Result.FAILURE, "节目更新失败！");
        }
    }

    @Override
    public Result updateShowP(Show show) {
        int rt = showMapper.updateShowP(show);
        if (rt == 1) {
            return new Result();
        } else {
            return new Result(Result.FAILURE, "节目更新失败！");
        }
    }

    @Override
    public void delShow(int showId) {
        showMapper.delShow(showId);
    }

    @Override
    public List<ShowResult> findShowResult() {
        return showMapper.findShowResult();
    }

}
